Skip to content

Commit b11c751

Browse files
committed
documenting the community-plugin benefit and adding more examples
1 parent 6f8c550 commit b11c751

File tree

4 files changed

+843
-1
lines changed

4 files changed

+843
-1
lines changed

plugin-gradle/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,28 @@ spotless {
468468
}
469469
```
470470

471+
<a name="prettier-plugins"></a>
472+
### Using community plugins for prettier
473+
474+
Since spotless uses the actual npm prettier package behind the scenes, it is possible to use prettier with
475+
community-plugins in order to support even more file types.
476+
477+
```gradle
478+
spotless {
479+
format 'prettierJava', {
480+
target '**/*.java'
481+
482+
prettier(['prettier': '2.0.5', 'prettier-plugin-java': '0.8.0']).config(['parser': 'java', 'tabWidth': 4])
483+
}
484+
format 'php', {
485+
target '**/*.php'
486+
prettier(['prettier': '2.0.5', '@prettier/plugin-php': '0.14.2']).config(['parser': 'php', 'tabWidth': 3])
487+
}
488+
}
489+
```
490+
471491
<a name="typescript-prettier"></a>
472-
Prettier can also be applied from within the [typescript config block](#typescript-formatter):
492+
### Note: Prettier can also be applied from within the [typescript config block](#typescript-formatter)
473493

474494
```gradle
475495
spotless {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package com.diffplug.gradle.spotless;
1717

18+
import java.io.File;
1819
import java.io.IOException;
20+
import java.nio.file.Files;
1921

2022
import org.assertj.core.api.Assertions;
2123
import org.gradle.testkit.runner.BuildResult;
@@ -92,4 +94,29 @@ public void useJavaCommunityPlugin() throws IOException {
9294
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
9395
assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
9496
}
97+
98+
@Test
99+
public void usePhpCommunityPlugin() throws IOException {
100+
setFile("build.gradle").toLines(
101+
"buildscript { repositories { mavenCentral() } }",
102+
"plugins {",
103+
" id 'com.diffplug.gradle.spotless'",
104+
"}",
105+
"def prettierConfig = [:]",
106+
"prettierConfig['tabWidth'] = 3",
107+
"prettierConfig['parser'] = 'php'",
108+
"def prettierPackages = [:]",
109+
"prettierPackages['prettier'] = '2.0.5'",
110+
"prettierPackages['@prettier/plugin-php'] = '0.14.2'",
111+
"spotless {",
112+
" format 'php', {",
113+
" target 'php-example.php'",
114+
" prettier(prettierPackages).config(prettierConfig)",
115+
" }",
116+
"}");
117+
setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty");
118+
final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
119+
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
120+
assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
121+
}
95122
}

0 commit comments

Comments
 (0)